$(document).ready(
//inital textarea
function() {
	$('#input').dblclick(textarea_click);
	$('#input').mouseup(textarea_click);
	
});

function synonymous_click(event){
	if($(this).attr('checked') == true){
		$('#input').replaceSelectedText($(this).val());
	}
	else{
		
	}
}



function textarea_click() {
	//alert("click double");
	$('#input').focus();
	var selectionObj = $('#input').getSelection();

	var selection = selectionObj.text.Trim();

	if (selection == '') {		
		return false;
	}	
	//get selection pass to services
	//http://localhost:8080/articlewritebee/
	var baseUrl = '/index.php/spin/query';

	$('#searchWord').val(selection.text);
	
	var request = $.ajax({
		type : 'POST',
		url : baseUrl,
		data : {
			word : selection.text
		},
		dataType : 'html'
	});

	request.fail(function(jqXHR, textStatus) {
		alert("Request failed: " + jqXHR.responseText);
	});
	request.done(function(msg) {
		$("#synonymousPanelList").html(msg);
		$('.check-with-label').bind("click",function(){
			var curr = $(this)[0];
			
			if(curr.checked == true){
				$('#input').replaceSelectedText(curr.value);
			}
			else{
				
			}
		});
	});
	jQuery.ajax(request);
}
